package org.bulu.project.web.controller;

import org.bulu.project.common.result.PageResult;
import org.bulu.project.common.result.Result;
import org.bulu.project.system.model.entity.Follow;
import org.bulu.project.system.model.query.UserFollowQuery;
import org.bulu.project.system.model.vo.UserFollowVO;
import org.bulu.project.system.security.SecurityUtils;
import org.bulu.project.system.service.FollowService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * (Follow)表控制层
 *
 * @author makejava
 * @since 2024-08-19 16:09:07
 */
@RestController
@RequestMapping("follow")
public class FollowController {
    /**
     * 服务对象
     */
    @Autowired
    private FollowService followService;

    /**
     * 分页查询所有关注数据
     * @param queryParams
     * @return
     */
    @PostMapping("/check")
    public PageResult<UserFollowVO> queryByPage(@RequestBody UserFollowQuery queryParams) {
        return PageResult.success(this.followService.checkUserFollow(queryParams));
    }

    /**
     * 获取当前用户所有的关注列表
     */
    @GetMapping("/getAllFollowing")
    public Result getFollowList() {
        List<Follow> result = followService.getFollowList();
        if (result == null){
            return Result.failed("查询结果为空");
        }else{
            return Result.success(result);
        }
    }

    /**
     * 删除数据（取关）
     * @param id 主键
     * @return 删除是否成功
     */
    @PostMapping("/del")
    public Result<?> delById(Integer id) {
        return Result.success(followService.delByIdInt(id));
    }

    /**
     * 新增数据（关注）
     * @param follow
     */
    @PostMapping("/add")
    public Result<?> addFollow(@RequestBody Follow follow) {
        return Result.success(followService.addFollow(follow));
    }

    /**
     * 更新数据（修改分组）
     * @param follow
     */
    @PostMapping("/update")
    public Result<?> updateGroup(@RequestBody Follow follow) {
        return Result.success(followService.updateGroup(follow));
    }
}